﻿//********************************************************************************//
//创建日期：<创建日期，2016-05-12>
//创建作者：<孙雪婷，sunxueting@shanghai3h.com>
//功能说明：用户信息查询
//********************************************************************************//
using BLL;
using BLL.Access;
using DevExpress.Web;
using Entity;
using System;
using System.Data;
using Web.Class;

namespace Web.Pages.YongShui._12.ChaXunGL
{
    public partial class YongHuXXCX_FY : BasePage
    {
        #region 属性

        /// <summary>
        /// 保存结果集1
        /// </summary>
        private DataTable dtYongHuXXTab1
        {
            get
            {
                return ViewState["dtYongHuXXTab1"] as DataTable;
            }
            set
            {
                ViewState["dtYongHuXXTab1"] = value;
            }
        }

        /// <summary>
        /// 保存结果集2
        /// </summary>
        private DataTable dtYongHuXXTab2
        {
            get
            {
                return ViewState["dtYongHuXXTab2"] as DataTable;
            }
            set
            {
                ViewState["dtYongHuXXTab2"] = value;
            }
        }

        /// <summary>
        /// 保存结果集3
        /// </summary>
        private DataTable dtYongHuXXTab2_N
        {
            get
            {
                return ViewState["dtYongHuXXTab2_N"] as DataTable;
            }
            set
            {
                ViewState["dtYongHuXXTab2_N"] = value;
            }
        }

        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int yonghuXXTab1_ID
        {
            get
            {
                return Convert.ToInt32(ViewState["yonghuXXTab1_ID"]);
            }
            set
            {
                ViewState["yonghuXXTab1_ID"] = value;
            }
        }
        /// <summary>
        /// 当前操作项ID
        /// </summary>
        private int yonghuXXTab2_ID
        {
            get
            {
                return Convert.ToInt32(ViewState["yonghuXXTab2_ID"]);
            }
            set
            {
                ViewState["yonghuXXTab2_ID"] = value;
            }
        }
        private int pageSize
        {
            get
            {
                return ViewState["pageSize"] == null ? 100 : Convert.ToInt32(ViewState["pageSize"]);
            }
            set
            {
                ViewState["pageSize"] = value;
            }
        }

        private int pageNo
        {
            get
            {
                return ViewState["pageNo"] == null ? 1 : Convert.ToInt32(ViewState["pageNo"]);
            }
            set
            {
                ViewState["pageNo"] = value;
            }
        }

        private int pagesCount
        {
            get
            {
                return ViewState["pagesCount"] == null ? 0 : Convert.ToInt32(ViewState["pagesCount"]);
            }
            set
            {
                ViewState["pagesCount"] = value;
            }
        }
        

        #endregion

        #region 变量

        /// <summary>
        /// 用户信息
        /// </summary>
        YS_YG_YONGHUXX _YS_YG_YONGHUXX = new YS_YG_YONGHUXX();

        /// <summary>
        /// 用户信息bll
        /// </summary>
        YS_YG_YONGHUXXBLL _YS_YG_YONGHUXXBLL = new YS_YG_YONGHUXXBLL();

        /// <summary>
        /// 管理部门
        /// </summary>
        YS_JX_ZHANDIAN _YS_JX_ZHANDIAN = new YS_JX_ZHANDIAN();

        /// <summary>
        /// 管理部门bll
        /// </summary>
        YS_JX_ZHANDIANBLL _YS_JX_ZHANDIANBLL = new YS_JX_ZHANDIANBLL();

        /// <summary>
        /// 管理块
        /// </summary>
        YS_JX_GUANLIK _YS_JX_GUANLIK = new YS_JX_GUANLIK();

        /// <summary>
        /// 管理块BLL
        /// </summary>
        YS_JX_GUANLIKBLL _YS_JX_GUANLIKBLL = new YS_JX_GUANLIKBLL();

       
        /// <summary>
        /// 局信息BLL
        /// </summary>
        YS_JX_JUXINXBLL _YS_JX_JUXINXBLL = new YS_JX_JUXINXBLL();

        /// <summary>
        /// 公司信息BLL
        /// </summary>
        YS_JX_GONGSIXXBLL _YS_JX_GONGSIXXBLL = new YS_JX_GONGSIXXBLL();

        /// <summary>
        /// 存储过程调用类
        /// </summary>
        SpHelper _SpHelper = new SpHelper();

        /// <summary>
        /// 来函用户调整
        /// </summary>
        YS_LH_YONGHUTZBLL _YS_LH_YONGHUTZBLL = new YS_LH_YONGHUTZBLL();
        
        #endregion

        #region 事件

        /// <summary>
        /// 页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            //第一次页面加载
            if (!IsPostBack)
            {
                InitData();
            }

            int index = ASPxPageControl1.ActiveTabIndex;

            gvYongHuXXTab1.DataSource = dtYongHuXXTab1;
            gvYongHuXXTab1.DataBind();

            gvFenHuXX.DataSource = dtYongHuXXTab2;
            gvFenHuXX.DataBind();
           
        }

      

        /// <summary>
        /// 查询信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnChaXun_Click(object sender, EventArgs e)
        {
            int index = ASPxPageControl1.ActiveTabIndex;
            if (index == 0)
            {
                if (txtShuiLiangYM.Text != "")
                {
                    LoadGridDataTab1();
                    if (this.dtYongHuXXTab1 == null || this.dtYongHuXXTab1.Rows.Count < 1)
                    {
                        txtYongHuH2.Text = "";
                        txtYongHuM2.Text = "";
                        txtYongShuiXZ.Text = "";
                        txtHangYeLX.Text = "";
                        txtJuHao.Text = "";
                        txtJuMing.Text = "";
                        txtYongShuiJ2.Text = "";
                        txtSheShuiDXFL.Text = "";
                        txtGongSiH.Text = "";
                        txtGongSiM.Text = "";
                        txtShouFeiFS.Text = "";
                        txtYeWuY.Text = "";
                        txtXingZhengQH.Text = "";
                        txtXingZhengQM.Text = "";
                        txtZiLaiSBS.Text = "";
                        txtHuiGuanBS.Text = "";
                        txtShiKaoHY2.Text = "";
                        txtKaoHeFYBZ.Text = "";
                        txtKaoHeFYBZ2.Text = "";
                        txtYongHuDZ2.Text = "";
                        txtLianXiBM.Text = "";
                        txtLianXiR.Text = "";
                        txtLianXiDH.Text = "";
                        txtYouBian.Text = "";
                        txtKaiHuHM2.Text = "";
                        txtKaiHuYH.Text = "";
                        txtYinHangZH2.Text = "";
                        zjltab1.Text = "共0条";
                    }

                }
            }
            else if (index == 1)
            {
                LoadGridDataTab2();
                if (this.dtYongHuXXTab2 == null || this.dtYongHuXXTab2.Rows.Count < 1)
                {
                    zjltab2.Text = "共0条";
                    gvFenHuJG.DataSource = null;
                    gvFenHuJG.DataBind();
                }
            }

        }


        /// <summary>
        /// 管理部门下拉改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmbGuanLiBM_SelectedIndexChanged(object sender, EventArgs e)
        {
            cmbGuanLiK.Items.Clear();
            //cmbGuanLiK.Items.Add("全部", "");
            cmbGuanLiK.SelectedIndex = 0;
            string glbm_now = cmbGuanLiBM.Value != null ? cmbGuanLiBM.Value.ToString() : "全部";
            InitDataAgain(glbm_now);

        }

        /// <summary>
        /// 表格点击行事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void gvYongHuXXTab1_FocusedRowChanged(object sender, EventArgs e)
        //{
        //    if (this.dtYongHuXXTab1 != null && this.dtYongHuXXTab1.Rows.Count > 0)
        //    {
        //        this.yonghuXXTab1_ID = Convert.ToInt32(this.gvYongHuXXTab1.GetRowValues(this.gvYongHuXXTab1.FocusedRowIndex, "ID"));
        //        SetData();
        //    }
        //}

        /// <summary>
        /// tab2下拉框改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void cmbHuJiGDLX_SelectedIndexChanged(object sender, EventArgs e)
        {
            LoadGridDataTab2();
        }

       
        #endregion

        #region 方法

        /// <summary>
        /// 初始化数据
        /// </summary>
        private void InitData()
        {
            //gvYongHuXXTab1.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            gvFenHuXX.SettingsPager.Mode = GridViewPagerMode.EndlessPaging;
            //水量年月
            string water_y_m = BusinessTool.YS_GETSETTINGSVALUE(eSETTINGS_KEYNAME.WATER_Y_M.ToString());
            //管理部门
            DataTable dtGuanLiBM = _YS_JX_ZHANDIANBLL.SelectYS_JX_ZHANDIANsAll();
            for (int i = 0; i < dtGuanLiBM.Rows.Count; i++)
            {
                if (dtGuanLiBM.Rows[i]["S_ZHANDIANMC"].ToString() != "中心")
                {
                    cmbGuanLiBM.Items.Add(dtGuanLiBM.Rows[i]["S_ZHANDIANMC"].ToString(), dtGuanLiBM.Rows[i]["S_ZHANDIANBH"].ToString());
                }
            }

            //业务员
            LoadYWY();
            txtShuiLiangYM.Text = water_y_m;

            //用水性质和涉水对象
            LoadYSXZ_SSDX();

            //加载局信息和公司信息
            LoadJXX_GSXX();

            int userid = LoginInfo.CurrentUser.UserID;
            string username = LoginInfo.CurrentUser.UserName;
            //根据操作人加载管理部门(站点)
            DataTable dtZhanDian = BusinessTool.GetTextAndValue("View_AS_UserInfo", "ZHANDIANBH", "ROLEID", null, string.Format("USERID={0}", userid)).Tables[0];
            string zhandian = dtZhanDian.Rows[0]["TEXT"].ToString();//站点
            string roleid = dtZhanDian.Rows[0]["VALUE"].ToString();//9001 业务员，3001 办事处主任
            if (roleid == "9001")
            {
                if (zhandian == "00")
                {
                    cmbYeWuY.Enabled = false;
                    cmbYeWuY.Text = username;
                }
                else
                {
                    cmbGuanLiBM.Enabled = false;
                    cmbYeWuY.Enabled = false;
                    cmbGuanLiBM.Value = zhandian;
                    cmbYeWuY.Text = username;
                    //管理块
                    DataTable dtGuanLiK = _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", zhandian), null);
                    for (int i = 0; i < dtGuanLiK.Rows.Count; i++)
                    {
                        cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(), dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                    }
                }
            }
            else if (roleid == "3001" || roleid == "4001")
            {
                cmbGuanLiBM.Enabled = false;
                cmbGuanLiBM.Value = zhandian;
                //管理块
                DataTable dtGuanLiK = _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", zhandian), null);
                for (int i = 0; i < dtGuanLiK.Rows.Count; i++)
                {
                    cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(), dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                }
                LoadYWY();
            }
        }

        /// <summary>
        /// 根据站点加载业务员
        /// </summary>
        private void LoadYWY()
        {
            DataTable dtYWY = BusinessTool.GetTextAndValue(
                "View_AS_UserInfo", "USERNAME", "USERID", null, this.cmbGuanLiBM.SelectedIndex == 0 ? "ROLENAME like '%业务员%'" : string.Format("ZHANDIANBH='{0}' and ROLENAME like '%业务员%'", this.cmbGuanLiBM.Value)
                 ).Tables[0];
            DataRow drTemp = dtYWY.NewRow();
            drTemp[0] = "";
            drTemp[1] = 0;
            dtYWY.Rows.InsertAt(drTemp, 0);
            PageTools.BindComboBox(
                this.cmbYeWuY, dtYWY
            );
            if (this.cmbYeWuY.Items.Count != 0)
            {
                this.cmbYeWuY.SelectedIndex = 0;
            }
        }

        /// <summary>
        /// 加载用水性质、涉水对象
        /// </summary>
        private void LoadYSXZ_SSDX()
        {
            //用水性质
            DataTable dt_ysxz = _SpHelper.P_YSCX_YSXZ_SSDX(1).Tables[0];
            for (int i = 0; i < dt_ysxz.Rows.Count; i++)
            {
                cmbYongShuiXZ.Items.Add(dt_ysxz.Rows[i]["XH"].ToString() + "_" + dt_ysxz.Rows[i]["NA"].ToString(), dt_ysxz.Rows[i]["XH"]);
            }
            //涉水对象
            DataTable dt_ssdx = _SpHelper.P_YSCX_YSXZ_SSDX(2).Tables[0];
            for (int i = 0; i < dt_ssdx.Rows.Count; i++)
            {
                cmbSheShuiDXFL_h1.Items.Add(dt_ssdx.Rows[i]["XH"].ToString() + "_" + dt_ssdx.Rows[i]["NA"].ToString(), dt_ssdx.Rows[i]["XH"]);
                cmbSheShuiDXFL_h2.Items.Add(dt_ssdx.Rows[i]["XH"].ToString() + "_" + dt_ssdx.Rows[i]["NA"].ToString(), dt_ssdx.Rows[i]["XH"]);

            }

        }

        /// <summary>
        /// 加载局信息和公司信息
        /// </summary>
        private void LoadJXX_GSXX()
        {
            DataTable dt_jxx = _YS_JX_JUXINXBLL.SelectYS_JX_JUXINXesDynamic("i_leixing=0 and i_jlzt=0", null);
            for (int i = 0; i < dt_jxx.Rows.Count; i++)
            {
                cbmJuXX.Items.Add(dt_jxx.Rows[i]["S_BIANHAO"].ToString() + "_" + dt_jxx.Rows[i]["S_MINGCHENG"].ToString(), dt_jxx.Rows[i]["S_BIANHAO"]);
            }

            DataTable dt_gsxx = _YS_JX_GONGSIXXBLL.SelectYS_JX_GONGSIXXesDynamic("i_leixing=0 and i_jlzt=0", null);
            for (int i = 0; i < dt_gsxx.Rows.Count; i++)
            {
                cmbGongSiXX.Items.Add(dt_gsxx.Rows[i]["S_BIANHAO"].ToString() + "_" + dt_gsxx.Rows[i]["S_MINGCHENG"].ToString(), dt_gsxx.Rows[i]["S_BIANHAO"]);
            }
        }

        /// <summary>
        /// 再次根据管理部门初始化查询条件
        /// </summary>
        /// <param name="glbm">管理部门</param>
        private void InitDataAgain(string glbm)
        {
            if (glbm != "全部")
            {
                //管理块
                DataTable dtGuanLiK = _YS_JX_GUANLIKBLL.SelectYS_JX_GUANLIKsDynamic(string.Format("S_ZHANDIAN={0}", glbm), null);
                for (int i = 0; i < dtGuanLiK.Rows.Count; i++)
                {
                    cmbGuanLiK.Items.Add(dtGuanLiK.Rows[i]["S_GUANLIKMC"].ToString(), dtGuanLiK.Rows[i]["S_GUANLIKH"].ToString());
                }
                //业务员
                LoadYWY();
            }
            else
            {
                cmbYeWuY.Items.Clear();
                //业务员
                LoadYWY();
            }

        }


        /// <summary>
        /// 加载查询数据
        /// </summary>
        private void LoadGridDataTab1()
        {
            string v_zhandian = "", v_guanlikuai = "", v_yonghuh = "", v_yonghum = "", v_yonghudz = "";
            int v_ym = Convert.ToInt32(txtShuiLiangYM.Text);
            string v_yinhangqr = "";
            int v_shoufeifs = 2;//收费方式 0 非托收，1托收
            string v_yongshuixz = "";
            string v_sheshuidx = "";
            string v_shikaohy = "";
            string v_yongshuij = "";
            string v_juxx = "";
            string v_gongsixx = "";
            string v_kaihuhm = "";
            string v_yinhangzh = "";
            string v_ywy = cmbYeWuY.Value.ToString() == "0" ? "" : cmbYeWuY.Value.ToString();
            //站点
            if (cmbGuanLiBM.Value != null)
            {
                v_zhandian = cmbGuanLiBM.Value.ToString();
            }
            //管理块
            if (cmbGuanLiK.Value != null)
            {
                v_guanlikuai = cmbGuanLiK.Value.ToString();
            }

            //用户号、用户名、用户地址
            if (rbnYongHuH.Checked && txtYongHuH.Text != "")
            {
                v_yonghuh = txtYongHuH.Text;
            }
            else if (rbnYongHuM.Checked && txtYongHuM.Text != "")
            {
                v_yonghum = txtYongHuM.Text;
            }
            else if (rbnYongHuDZ.Checked && txtYongHuDZ.Text != "")
            {
                v_yonghudz = txtYongHuDZ.Text;
            }
            else if (rbnShouFeiFS.Checked && cmbShouFeiFS.Text != "") //收费方式
            {
                v_shoufeifs = Convert.ToInt32(cmbShouFeiFS.Value);
            }
            else if (rbnYongShuiXZ.Checked && cmbYongShuiXZ.Text != "")//用水性质
            {
                v_yongshuixz = cmbYongShuiXZ.Value.ToString();
            }
            else if (rbnSheShuiDXFL.Checked)//涉水对象分类
            {
                if (cmbSheShuiDXFL_q1.Text != "" && cmbSheShuiDXFL_h1.Text != "")
                {
                    v_sheshuidx = cmbSheShuiDXFL_q1.Text + cmbSheShuiDXFL_h1.Value.ToString();
                    if (cmbSheShuiDXFL_q2.Text != "" && cmbSheShuiDXFL_h2.Text != "")
                    {
                        v_sheshuidx += " AND  S_SHESHUIDXDM ";
                        v_sheshuidx += cmbSheShuiDXFL_q2.Text + cmbSheShuiDXFL_h2.Value.ToString();
                    }
                }
            }
            else if (rbnShiKaoHY.Checked && cbmShiKaoHY.Text != "" && txtShiKaoHY.Text != "")//试考核月
            {
                v_shikaohy = cbmShiKaoHY.Text + txtShiKaoHY.Text;
            }
            else if (rbnYongShuiJ.Checked && cbmYongShuiJ.Text != "" && txtYongShuiJ.Text != "")//用水价
            {
                v_yongshuij = cbmYongShuiJ.Text + txtYongShuiJ.Text;
            }
            else if (rbnJuXX.Checked && cbmJuXX.Text != "")//局信息
            {
                v_juxx = cbmJuXX.Value.ToString();
            }
            else if (rbnGongSiXX.Checked && cmbGongSiXX.Text != "")//公司信息
            {
                v_gongsixx = cmbGongSiXX.Value.ToString();
            }
            else if (rbnKaiHuHM.Checked && txtKaiHuHM.Text != "")//开户户名
            {
                v_kaihuhm = txtKaiHuHM.Value.ToString();
            }
            else if (rbnYinHangZH.Checked && txtYinHangZH.Text != "")//银行帐号
            {
                v_yinhangzh = txtYinHangZH.Value.ToString();
            }
            //this.dtYongHuXXTab1
            //dtYongHuXXTab1 = _SpHelper.P_YSCX_YHXXCX(v_zhandian, v_guanlikuai, v_ywy, v_ym, v_yonghuh, v_yonghum, v_yonghudz,
            //    v_shoufeifs, v_yongshuixz, v_sheshuidx, v_shikaohy, v_yongshuij, v_juxx, v_gongsixx, v_kaihuhm, v_yinhangzh, 0, v_yinhangqr).Tables[0];
            int? pCount=0;
            int psize = -1;
            if (int.TryParse(this.txtPageSize.Text, out psize))
            {
                this.pageSize = psize;
            }
            else
            {
                this.pageSize = 100;
            }
            dtYongHuXXTab1 = _SpHelper.P_YSCX_YHXXCX_PAGE(v_zhandian, v_guanlikuai, v_ywy, v_ym, v_yonghuh, v_yonghum, v_yonghudz,
                v_shoufeifs, v_yongshuixz, v_sheshuidx, v_shikaohy, v_yongshuij, v_juxx, v_gongsixx, v_kaihuhm, v_yinhangzh, 0, v_yinhangqr,
                0, this.pageSize, this.pageNo, out pCount).Tables[0];
            this.pagesCount = (int)pCount;            
            gvYongHuXXTab1.DataSource = dtYongHuXXTab1;
            gvYongHuXXTab1.DataBind();
            this.cpPageNo.Text = this.pageNo.ToString();
            this.cpRecordsCount.Text = pCount.ToString();
            this.pagesCount = (pCount % this.pageSize == 0) ? (int)pCount / this.pageSize : (int)pCount / this.pageSize + 1;
            this.cpPagesCount.Text = this.pagesCount.ToString();
            //this.dtYongHuXXTab1 = dt;
            if (dtYongHuXXTab1 != null && dtYongHuXXTab1.Rows.Count > 0)
            {
                zjltab1.Text = "当前" + this.dtYongHuXXTab1.Rows.Count.ToString() + "条";
                gvYongHuXXTab1.FocusedRowIndex = 0;
                SetData();
            }
        }

        /// <summary>
        /// 给显示框赋值
        /// </summary>
        private void SetData()
        {
            DataTable dt_temp = _SpHelper.P_YSCX_YHXXCX("", "", "", Convert.ToInt32(txtShuiLiangYM.Text), "", "", "", 2, "", "", "", "", "", "", "", "", Convert.ToInt32(gvYongHuXXTab1.GetRowValues(0, "ID")), "").Tables[0];
            if (dt_temp != null && dt_temp.Rows.Count > 0)
            {
                txtYongHuH2.Text = dt_temp.Rows[0]["用户号"].ToString();
                txtYongHuM2.Text = dt_temp.Rows[0]["用户名"].ToString();
                txtYongShuiXZ.Text = dt_temp.Rows[0]["用水性质"].ToString();
                txtHangYeLX.Text = "";
                txtJuHao.Text = dt_temp.Rows[0]["局号"].ToString();
                txtJuMing.Text = dt_temp.Rows[0]["局名"].ToString();
                txtYongShuiJ2.Text = dt_temp.Rows[0]["用水价"].ToString();
                txtSheShuiDXFL.Text = dt_temp.Rows[0]["涉水对象"].ToString();
                txtGongSiH.Text = dt_temp.Rows[0]["公司号"].ToString();
                txtGongSiM.Text = dt_temp.Rows[0]["公司名"].ToString();
                txtShouFeiFS.Text = dt_temp.Rows[0]["收费方式"].ToString();
                txtYeWuY.Text = dt_temp.Rows[0]["业务员"].ToString();
                txtXingZhengQH.Text = dt_temp.Rows[0]["行政区号"].ToString();
                txtXingZhengQM.Text = dt_temp.Rows[0]["行政区"].ToString();
                txtZiLaiSBS.Text = "0";
                txtHuiGuanBS.Text = "";
                txtShiKaoHY2.Text = dt_temp.Rows[0]["考核复用"].ToString();
                txtKaoHeFYBZ.Text = "不考核";
                txtKaoHeFYBZ2.Text = dt_temp.Rows[0]["试考核月"].ToString();
                txtYongHuDZ2.Text = dt_temp.Rows[0]["用户地址"].ToString();
                txtLianXiBM.Text = dt_temp.Rows[0]["联系部门"].ToString();
                txtLianXiR.Text = dt_temp.Rows[0]["联系人"].ToString();
                txtLianXiDH.Text = dt_temp.Rows[0]["联系电话"].ToString();
                txtYouBian.Text = dt_temp.Rows[0]["邮编"].ToString();
                txtKaiHuHM2.Text = dt_temp.Rows[0]["开户户名"].ToString();
                txtKaiHuYH.Text = dt_temp.Rows[0]["开户银行"].ToString();
                txtYinHangZH2.Text = dt_temp.Rows[0]["银行账号"].ToString();

            }
        }
        /// <summary>
        /// 加载tab2页签数据
        /// </summary>
        private void LoadGridDataTab2()
        {
            int val = Convert.ToInt32(cmbHuJiGDLX.Value);
            if (val == 1)
            {
                legend1.InnerText = "分户前用户信息";
                legend2.InnerText = "分户结果";
            }
            else if (val == 2)
            {
                legend1.InnerText = "并户结果";
                legend2.InnerText = "并户前用户信息";
            }
            else if (val == 4)
            {
                legend1.InnerText = "改户前信息";
                legend2.InnerText = "改户结果";
            }
            else if (val == 5)
            {
                legend1.InnerText = "销户前信息";
                legend2.InnerText = "销户结果";
            }

            if (val == 2)
            {
                //并户结果
                this.dtYongHuXXTab2 = _SpHelper.P_YSCX_YHXXCX_BH().Tables[0];
                this.gvFenHuXX.DataSource = this.dtYongHuXXTab2;
                this.gvFenHuXX.DataBind();
                //                select * from ys_lh_yonghutz   where  i_yuanyongh=1 and i_laihanlx=9
                //and (s_laihanbh is null or exists(select 1 from ys_lh_laihanxx a where a.i_laihanlx=9 and a.s_laihanbh=s_laihanbh 
                //and a.i_liuchengzt=1)) order by s_yonghuh;
                //                select * from customer 
                //where i_state=-1 and i_Action=2
                //and c_userid in (0100503,0101115)
                //and i_jlzt=0;
            }
            else
            {
                this.dtYongHuXXTab2 = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format(" i_jlzt=-1 and i_leixing=0 and I_YONGHUZT={0} order by s_yonghuh", val), null);
                this.gvFenHuXX.DataSource = this.dtYongHuXXTab2;
                this.gvFenHuXX.DataBind();
            }
            if (this.dtYongHuXXTab2 != null && this.dtYongHuXXTab2.Rows.Count > 0)
            {
                zjltab2.Text = "共" + this.dtYongHuXXTab2.Rows.Count.ToString() + "条";
                gvFenHuXX.FocusedRowIndex = 0;
                //LoadGridDataTab2_N(val);
            }
        }

        /// <summary>
        /// 根据上面信息显示下列结果
        /// </summary>
        private void LoadGridDataTab2_N(int val)
        {
                DataTable dt_temp = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format(" ID='{0}'", this.yonghuXXTab2_ID), null);
                if (dt_temp != null && dt_temp.Rows.Count > 0)
                {
                    string sYuanYHH = dt_temp.Rows[0]["S_YONGHUH"].ToString();
                    if (sYuanYHH != "")
                    {
                        this.dtYongHuXXTab2_N = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("i_leixing=0 and s_yuanyonghuh in ({0}) order by s_yonghuh", sYuanYHH), null);
                        this.gvFenHuJG.DataSource = this.dtYongHuXXTab2_N;
                        this.gvFenHuJG.DataBind();
                    }
                }
            
        }

        /// <summary>
        /// 前台表格行改变事件回调方法
        /// </summary>
        /// <param name="source"></param>
        /// <param name="e"></param>
        protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
        {
            int id = Convert.ToInt32(this.hdCollection.Get("ID"));
            if (e.Parameter == "setinfo")
            {
                string msg = "";
                DataTable dt_temp = _SpHelper.P_YSCX_YHXXCX("", "", "", Convert.ToInt32(txtShuiLiangYM.Text), "", "", "", 2, "", "", "", "", "", "", "", "", id, "").Tables[0];
                if (dt_temp != null && dt_temp.Rows.Count > 0)
                {
                    msg = string.Join("|", Convert.ToString(dt_temp.Rows[0]["用户号"]), Convert.ToString(dt_temp.Rows[0]["用户名"]), Convert.ToString(dt_temp.Rows[0]["用水性质"]),
                        Convert.ToString(dt_temp.Rows[0]["局号"]), Convert.ToString(dt_temp.Rows[0]["局名"]), Convert.ToString(dt_temp.Rows[0]["用水价"]), Convert.ToString(dt_temp.Rows[0]["涉水对象"]),
                        Convert.ToString(dt_temp.Rows[0]["公司号"]), Convert.ToString(dt_temp.Rows[0]["公司名"]), Convert.ToString(dt_temp.Rows[0]["收费方式"]), Convert.ToString(dt_temp.Rows[0]["业务员"]),
                        Convert.ToString(dt_temp.Rows[0]["行政区号"]), Convert.ToString(dt_temp.Rows[0]["行政区"]), Convert.ToString(dt_temp.Rows[0]["考核复用"]), Convert.ToString(dt_temp.Rows[0]["试考核月"]),
                        Convert.ToString(dt_temp.Rows[0]["用户地址"]), Convert.ToString(dt_temp.Rows[0]["联系部门"]), Convert.ToString(dt_temp.Rows[0]["联系人"]), Convert.ToString(dt_temp.Rows[0]["联系电话"]),
                        Convert.ToString(dt_temp.Rows[0]["邮编"]), Convert.ToString(dt_temp.Rows[0]["开户户名"]), Convert.ToString(dt_temp.Rows[0]["开户银行"]), Convert.ToString(dt_temp.Rows[0]["银行账号"]),
                        dt_temp.Rows[0]["I_ZLSBS"].ToString(), dt_temp.Rows[0]["I_HGBS"].ToString());
                }
                e.Result = e.Parameter + "|0|" + msg;
            }
            else if (e.Parameter == "hjgdxx")
            {
                int val = Convert.ToInt32(cmbHuJiGDLX.Value);
                DataTable dt_temp = new DataTable();
                string msg = "";
                string sYuanYHH = "";
                if (val == 2)
                {
                    dt_temp = _YS_LH_YONGHUTZBLL.SelectYS_LH_YONGHUTZsDynamic(string.Format(" ID='{0}'", id), null);
                    sYuanYHH = dt_temp != null && dt_temp.Rows.Count > 0 ? dt_temp.Rows[0]["S_YUANYONGHUH"].ToString() : "";
                }
                else
                {
                    dt_temp = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format(" ID='{0}'", id), null);
                    sYuanYHH = dt_temp != null && dt_temp.Rows.Count > 0 ? dt_temp.Rows[0]["S_YONGHUH"].ToString() : "";
                }
                msg = string.Join("|", Convert.ToString(sYuanYHH));
                e.Result = e.Parameter + "|0|" + msg;

            }
        }

        /// <summary>
        /// 分户结果刷新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvFenHuJG_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
        {
            string yhh = this.hdCollection.Get("yyhh").ToString();
            int val = Convert.ToInt32(cmbHuJiGDLX.Value);
            if (val == 2)
            {
                string[] arryhh = yhh.Split(',');
                string yhh2 = "'" + string.Join("','", arryhh) + "'";
                this.dtYongHuXXTab2_N = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("I_LEIXING=0 AND S_YONGHUH in ({0}) order by s_yonghuh", yhh2), null);
            }
            else
            {
                this.dtYongHuXXTab2_N = _YS_YG_YONGHUXXBLL.SelectYS_YG_YONGHUXXesDynamic(string.Format("I_LEIXING=0 AND S_YUANYONGHUH = '{0}' order by s_yonghuh", yhh), null);
            }



            this.gvFenHuJG.DataSource = this.dtYongHuXXTab2_N;
            this.gvFenHuJG.DataBind();
        }
        #endregion

        protected void cpPre_Click(object sender, EventArgs e)
        {
            this.pageNo--;
            if(this.pageNo==0)
            {
                this.pageNo = 1;
            }
            LoadGridDataTab1();

        }

        protected void cpNext_Click(object sender, EventArgs e)
        {
            this.pageNo++;
            if (this.pageNo > this.pagesCount)
            {
                this.pageNo = this.pagesCount;
            }
            LoadGridDataTab1();
        }

        protected void cpGoTo_Click(object sender, EventArgs e)
        {
            int gotoP=-1;
            if (!int.TryParse(this.cpGoToV.Text, out gotoP))
            {
                return;
            }
            if(gotoP>=this.pagesCount)
            {
                gotoP = this.pagesCount;
            }
            this.pageNo = gotoP;
            LoadGridDataTab1();
        }



    }
}